package com.dxd.onlineshop.pojo;

import lombok.*;

import java.math.BigDecimal;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class OrderItem {
    private Integer orderItemId; //主键
    private Integer orderId; //所属订单ID
    private Integer productId; //产品ID
    private String productName; //产品名
    @Setter
    private Integer quantity; //数量
    @Setter
    private BigDecimal unitPrice; //商品单价

    @Builder.Default
    private Boolean isSelected = true; //是否被选中

    //计算每一项订单项需支付的金额
    public BigDecimal getSubtotal() {
        return (quantity != null && unitPrice != null)
                ? unitPrice.multiply(BigDecimal.valueOf(quantity))
                : BigDecimal.ZERO;
    }

}